<!DOCTYPE html><html><head><title>Ext.util.Inflector | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
<style type="text/css">.head-band { display: none; }
.header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
.doc-tab .members .member a.more { background-color: #efefef; }
</style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
</head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
<a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">

    req = {
        liveURL: '.',
        standAloneMode: true,
        origDocClass: 'Ext.util.Inflector',
        docClass: 'Ext.util.Inflector',
        docReq: 'Ext.util.Inflector',
        version: '4.0',
        baseURL: '.',
        baseDocURL: '.',
        baseProdURL: '.'
    };

    clsInfo = {};



</script>

<script type="text/javascript" src="../search.js"></script>
<!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
<script type="text/javascript" src="../class_tree.js"></script>
<script type="text/javascript" src="../class_doc.js"></script>
<script type="text/javascript">
    req.source = 'Inflector.html#Ext-util.Inflector';
    clsInfo = {"methods":["classify","clearPlurals","clearSingulars","isTransnumeral","ordinalize","plural","pluralize","singular","singularize"],"cfgs":[],"properties":[],"events":[],"subclasses":[]};
    Ext.onReady(function() {
        Ext.create('Docs.classPanel');
    });
</script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/Inflector.html#Ext-util.Inflector" target="_blank">Ext.util.Inflector</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>General purpose inflector class that <a href="Ext.util.Inflector.html#pluralize" rel="Ext.util.Inflector#pluralize" class="docClass">pluralizes</a>, <a href="Ext.util.Inflector.html#singularize" rel="Ext.util.Inflector#singularize" class="docClass">singularizes</a> and 
<a href="Ext.util.Inflector.html#ordinalize" rel="Ext.util.Inflector#ordinalize" class="docClass">ordinalizes</a> words. Sample usage:</p>




<pre class="prettyprint"><code>//turning singular words into plurals
Ext.util.Inflector.pluralize('word'); //'words'
Ext.util.Inflector.pluralize('person'); //'people'
Ext.util.Inflector.pluralize('sheep'); //'sheep'

//turning plurals into singulars
Ext.util.Inflector.singularize('words'); //'word'
Ext.util.Inflector.singularize('people'); //'person'
Ext.util.Inflector.singularize('sheep'); //'sheep'

//ordinalizing numbers
Ext.util.Inflector.ordinalize(11); //"11th"
Ext.util.Inflector.ordinalize(21); //"21th"
Ext.util.Inflector.ordinalize(1043); //"1043rd"
</code></pre>




<p><u>Customization</u></p>




<p>The Inflector comes with a default set of US English pluralization rules. These can be augmented with additional
rules if the default rules do not meet your application's requirements, or swapped out entirely for other languages.
Here is how we might add a rule that pluralizes "ox" to "oxen":</p>




<pre class="prettyprint"><code>Ext.util.Inflector.plural(/^(ox)$/i, "$1en");
</code></pre>




<p>Each rule consists of two items - a regular expression that matches one or more rules, and a replacement string.
In this case, the regular expression will only match the string "ox", and will replace that match with "oxen". 
Here's how we could add the inverse rule:</p>




<pre class="prettyprint"><code>Ext.util.Inflector.singular(/^(ox)en$/i, "$1");
</code></pre>




<p>Note that the ox/oxen rules are present by default.</p>

<div class="members"><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-classify" class="member f ni"><a href="Ext.util.Inflector.html#method-classify" rel="method-classify" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-classify" class="viewSource">view source</a></div><a name="classify"></a><a name="method-classify"></a><a href="Ext.util.Inflector.html#" rel="method-classify" class="cls expand">classify</a>(
<span class="pre">String word</span>)
 : String</div><div class="description"><div class="short"><p>Returns the correct <a href="Ext.data.Model.html" rel="Ext.data.Model" class="docClass">Model</a> name for a given string. Mostly used internally by the data
package</p>
</div><div class="long"><p>Returns the correct <a href="Ext.data.Model.html" rel="Ext.data.Model" class="docClass">Model</a> name for a given string. Mostly used internally by the data
package</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">word</span> : String<div class="sub-desc"><p>The word to classify</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">String</span>&nbsp; &nbsp;<p>The classified version of the word</p>
</li></ul></div></div></div><div id="method-clearPlurals" class="member ni"><a href="Ext.util.Inflector.html#method-clearPlurals" rel="method-clearPlurals" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-clearPlurals" class="viewSource">view source</a></div><a name="clearPlurals"></a><a name="method-clearPlurals"></a><a href="Ext.util.Inflector.html#" rel="method-clearPlurals" class="cls expand">clearPlurals</a> : void</div><div class="description"><div class="short"><p>Removes all registered pluralization rules</p>
</div><div class="long"><p>Removes all registered pluralization rules</p>
<h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-clearSingulars" class="member ni"><a href="Ext.util.Inflector.html#method-clearSingulars" rel="method-clearSingulars" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-clearSingulars" class="viewSource">view source</a></div><a name="clearSingulars"></a><a name="method-clearSingulars"></a><a href="Ext.util.Inflector.html#" rel="method-clearSingulars" class="cls expand">clearSingulars</a> : void</div><div class="description"><div class="short"><p>Removes all registered singularization rules</p>
</div><div class="long"><p>Removes all registered singularization rules</p>
<h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-isTransnumeral" class="member ni"><a href="Ext.util.Inflector.html#method-isTransnumeral" rel="method-isTransnumeral" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-isTransnumeral" class="viewSource">view source</a></div><a name="isTransnumeral"></a><a name="method-isTransnumeral"></a><a href="Ext.util.Inflector.html#" rel="method-isTransnumeral" class="cls expand">isTransnumeral</a>(
<span class="pre">String word</span>)
 : Boolean</div><div class="description"><div class="short"><p>Returns true if the given word is transnumeral (the word is its own singular and plural form - e.g. sheep, fish)</p>
</div><div class="long"><p>Returns true if the given word is transnumeral (the word is its own singular and plural form - e.g. sheep, fish)</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">word</span> : String<div class="sub-desc"><p>The word to test</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Boolean</span>&nbsp; &nbsp;<p>True if the word is transnumeral</p>
</li></ul></div></div></div><div id="method-ordinalize" class="member ni"><a href="Ext.util.Inflector.html#method-ordinalize" rel="method-ordinalize" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-ordinalize" class="viewSource">view source</a></div><a name="ordinalize"></a><a name="method-ordinalize"></a><a href="Ext.util.Inflector.html#" rel="method-ordinalize" class="cls expand">ordinalize</a>(
<span class="pre">Number number</span>)
 : String</div><div class="description"><div class="short">Ordinalizes a given number by adding a prefix such as 'st', 'nd', 'rd' or 'th' based on the last digit of the
number....</div><div class="long"><p>Ordinalizes a given number by adding a prefix such as 'st', 'nd', 'rd' or 'th' based on the last digit of the
number. 21 -> 21st, 22 -> 22nd, 23 -> 23rd, 24 -> 24th etc</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">number</span> : Number<div class="sub-desc"><p>The number to ordinalize</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">String</span>&nbsp; &nbsp;<p>The ordinalized number</p>
</li></ul></div></div></div><div id="method-plural" class="member ni"><a href="Ext.util.Inflector.html#method-plural" rel="method-plural" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-plural" class="viewSource">view source</a></div><a name="plural"></a><a name="method-plural"></a><a href="Ext.util.Inflector.html#" rel="method-plural" class="cls expand">plural</a>(
<span class="pre">RegExp matcher, String replacer</span>)
 : void</div><div class="description"><div class="short"><p>Adds a new pluralization rule to the Inflector. See the intro docs for more information</p>
</div><div class="long"><p>Adds a new pluralization rule to the Inflector. See the intro docs for more information</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">matcher</span> : RegExp<div class="sub-desc"><p>The matcher regex</p>
</div></li><li><span class="pre">replacer</span> : String<div class="sub-desc"><p>The replacement string, which can reference matches from the matcher argument</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-pluralize" class="member ni"><a href="Ext.util.Inflector.html#method-pluralize" rel="method-pluralize" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-pluralize" class="viewSource">view source</a></div><a name="pluralize"></a><a name="method-pluralize"></a><a href="Ext.util.Inflector.html#" rel="method-pluralize" class="cls expand">pluralize</a>(
<span class="pre">String word</span>)
 : String</div><div class="description"><div class="short"><p>Returns the pluralized form of a word (e.g. Ext.util.Inflector.pluralize('word') returns 'words')</p>
</div><div class="long"><p>Returns the pluralized form of a word (e.g. Ext.util.Inflector.pluralize('word') returns 'words')</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">word</span> : String<div class="sub-desc"><p>The word to pluralize</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">String</span>&nbsp; &nbsp;<p>The pluralized form of the word</p>
</li></ul></div></div></div><div id="method-singular" class="member ni"><a href="Ext.util.Inflector.html#method-singular" rel="method-singular" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-singular" class="viewSource">view source</a></div><a name="singular"></a><a name="method-singular"></a><a href="Ext.util.Inflector.html#" rel="method-singular" class="cls expand">singular</a>(
<span class="pre">RegExp matcher, String replacer</span>)
 : void</div><div class="description"><div class="short"><p>Adds a new singularization rule to the Inflector. See the intro docs for more information</p>
</div><div class="long"><p>Adds a new singularization rule to the Inflector. See the intro docs for more information</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">matcher</span> : RegExp<div class="sub-desc"><p>The matcher regex</p>
</div></li><li><span class="pre">replacer</span> : String<div class="sub-desc"><p>The replacement string, which can reference matches from the matcher argument</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
</li></ul></div></div></div><div id="method-singularize" class="member ni"><a href="Ext.util.Inflector.html#method-singularize" rel="method-singularize" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.util.Inflector.html" class="definedIn docClass">Ext.util.Inflector</a><br/><a href="../source/Inflector.html#Ext-util.Inflector-method-singularize" class="viewSource">view source</a></div><a name="singularize"></a><a name="method-singularize"></a><a href="Ext.util.Inflector.html#" rel="method-singularize" class="cls expand">singularize</a>(
<span class="pre">String word</span>)
 : String</div><div class="description"><div class="short"><p>Returns the singularized form of a word (e.g. Ext.util.Inflector.singularize('words') returns 'word')</p>
</div><div class="long"><p>Returns the singularized form of a word (e.g. Ext.util.Inflector.singularize('words') returns 'word')</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">word</span> : String<div class="sub-desc"><p>The word to singularize</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">String</span>&nbsp; &nbsp;<p>The singularized form of the word</p>
</li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>